<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class ActPrizeRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $createRules = [
            'name'    => 'required',
            'content' => 'required',
            'type'    => 'required|numeric',
            'chances' => 'required|numeric',
            'act_id'  => 'required|numeric',
            'num'     => 'required|numeric',
            'sort'    => 'required|numeric|unique:act_prize,sort',

        ];

        $editRules = [
            'id'      => 'required|numeric',
            'name'    => 'required',
            'content' => 'required',
            'type'    => 'required|numeric',
            'chances' => 'required|numeric',
            'act_id'  => 'required|numeric',
            'num'     => 'required|numeric',
            'sort'    => 'required|numeric',

        ];
//        return array();

        $data = Request::all();
        if ($data['formType'] == 'create') {
            return $createRules;
        }

        return $editRules;
    }

    public function attributes()
    {
        $attributes = array(
            'name'    => '奖品名称',
            'content' => '奖品内容',
            'type'    => '奖品类型',
            'chances' => '概率',
            'act_id'  => '所属于的活动',
            'num'     => '数量',
        );

//        return array();

        return $attributes;
    }

    public function messages()
    {
        $messages = [
            'required'    => ':attribute为必填选项',
            'numeric'     => ':attribute必须为数字',
            'sort.unique' => ':attribute必须不能和别的奖项的sort重复',
        ];

        return $messages;
    }
}
